package com.alameda.common.commonpent.event.publisher;

import com.alameda.common.commonpent.event.message.EventMessage;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * spring事件监听 事件发布对象
 *
 * @author Lv
 * @date 2025/1/4
 */
@Component
public class EventPublisher {
    /**
     * spring上下文对象
     */
    private final ApplicationContext applicationContext;

    /**
     * 构造函数注入
     *
     * @param applicationContext spring上下文对象
     */
    public EventPublisher(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    /**
     * 事件发布
     *
     * @param message 消息内容
     */
    public void publish(String message) {
        EventMessage event = new EventMessage(this, message);
        applicationContext.publishEvent(event);
    }
}